package com.caojm.mptools.commands;

import com.caojm.mptools.Mptools;
import com.caojm.mptools.utils.DatabaseHelper;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text;

public class StatusCommand {

    // 注册命令
    public static void register(){
        // 注册 '/mp status' 命令
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
                dispatcher.register(
                        CommandManager.literal("mp")
                                .then(CommandManager.literal("status")
                                        .executes(context -> {
                                            ServerCommandSource source = context.getSource();
                                            String playerName = source.getName();

                                            // 检查玩家是否已绑定账号
                                            String websiteAccount = DatabaseHelper.getAccount(playerName);

                                            if (websiteAccount != null && !websiteAccount.isEmpty()) {
                                                // 如果玩家已经绑定，输出绑定状态
                                                source.sendFeedback(() -> Text.of("玩家 " + playerName + " 已绑定官网账号: " + websiteAccount), false);
                                                Mptools.LOGGER.info("玩家 " + playerName + " 已绑定官网账号: " + websiteAccount);
                                            } else {
                                                // 如果玩家没有绑定，返回未绑定状态
                                                source.sendFeedback(() -> Text.of("玩家 " + playerName + " 尚未绑定官网账号。"), false);
                                                Mptools.LOGGER.info("玩家 " + playerName + " 尚未绑定账号。");
                                            }

                                            return 1;  // 命令成功执行
                                        })
                                )
                )
        );
    }
    }

